//
//  ElectronTicketViewController.m
//  PropertyManager
//
//  Created by TNG on 2018/8/1.
//  Copyright © 2018年 Tng. All rights reserved.
//

#import "ElectronTicketViewController.h"

@interface ElectronTicketViewController () <UITableViewDelegate,UITableViewDataSource>

@property (strong, nonatomic) UITableView * tableview;
@property (strong, nonatomic) UIButton * sureBtn;

@end

@implementation ElectronTicketViewController

static NSString * cellID = @"cell";
static NSString * ElectrolTicketOrderTableViewCellID = @"ElectrolTicketOrderTableViewCell";
static NSString * ElectronPayMedthodTableViewCellID = @"ElectronPayMedthodTableViewCell";
static NSString * ElectronNumTableViewCellID = @"ElectronNumTableViewCell";
static NSString * ElectorTicketNullTableViewCellID = @"ElectorTicketNullTableViewCell";


- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.title = @"电子发票";
    [self creatTableview];
    [self registCell];
    [self.view addSubview:self.sureBtn];
}

-(void)registCell
{
    [self.tableview registerClass:[UITableViewCell class] forCellReuseIdentifier:cellID];
    [self.tableview registerClass:[ElectrolTicketOrderTableViewCell class] forCellReuseIdentifier:ElectrolTicketOrderTableViewCellID];
    [self.tableview registerClass:[ElectronPayMedthodTableViewCell class] forCellReuseIdentifier:ElectronPayMedthodTableViewCellID];
    [self.tableview registerClass:[ElectronNumTableViewCell class] forCellReuseIdentifier:ElectronNumTableViewCellID];
    [self.tableview registerClass:[ElectorTicketNullTableViewCell class] forCellReuseIdentifier:ElectorTicketNullTableViewCellID];
}

-(void)creatTableview{
    if (self.tableview == nil) {
        UITableView * tableview = [[UITableView alloc] initWithFrame:CGRectMake(0, kStatusAndNavBarH, WIDTH, HEIGHT - kStatusAndNavBarH - kHomeLineH - 50) style:UITableViewStyleGrouped];
        tableview.delegate = self;
        tableview.dataSource = self;
        tableview.separatorStyle = UITableViewCellSeparatorStyleNone;
        if (@available(iOS 11.0, *)) {
            tableview.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentAutomatic;
        }
        self.tableview = tableview;
        [self.view addSubview:self.tableview];
    }
}

-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    return [UIView new];
}

-(UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
{
    return [UIView new];
}

-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 0.01;
}

-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    return 0.01;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.row == 0) {
        return 205;
    }else if (indexPath.row == 1)
    {
        return 192;
    }else if(indexPath.row == 5)
    {
        return 15;
    }else
    {
        return 25;
    }
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 6;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.row == 0) {
        ElectrolTicketOrderTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:ElectrolTicketOrderTableViewCellID];
        [cell send];
        return cell;
    }else if (indexPath.row == 1)
    {
        ElectronPayMedthodTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:ElectronPayMedthodTableViewCellID];
        [cell send];
        return cell;
    }else if(indexPath.row == 5)
    {
        ElectorTicketNullTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:ElectorTicketNullTableViewCellID];
        return cell;
    }else
    {
        ElectronNumTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:ElectronNumTableViewCellID];
        if(indexPath.row == 2)
        {
            cell.titleLabel.text = @"租金";
            cell.moneyLabel.text = @"￥10";
        }else if(indexPath.row == 3)
        {
            cell.titleLabel.text = @"管理费";
            cell.moneyLabel.text = @"￥45";
        }else{
            cell.titleLabel.text = @"总计";
            cell.moneyLabel.text = @"￥55";
            cell.moneyLabel.font = font(24);
            cell.moneyLabel.textColor = SFMColor(246, 110, 36);
        }
        return cell;
    }
//    UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:cellID];
//    return cell;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
}

-(UIButton *)sureBtn
{
    if (_sureBtn == nil) {
        _sureBtn = [[UIButton alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(self.tableview.frame), WIDTH, 50)];
        [_sureBtn setTitle:@"确定" forState:UIControlStateNormal];
        [_sureBtn setBackgroundColor:SFMNavBarColor];
        _sureBtn.titleLabel.font = font(16);
        [_sureBtn addTarget:self action:@selector(sureBtnClick:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _sureBtn;
}

#pragma mark - 确定事件
-(void)sureBtnClick:(UIButton *)btn
{
    NSArray * arr = self.navigationController.viewControllers;
    PayMoneyRecodeViewController * ctr = [self.navigationController.viewControllers objectAtIndex:arr.count - 4];
    [self.navigationController popToViewController:ctr animated:YES];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
